package com.atguigu.crowd.filter;

import atguigu.crowd.util.ResultEntity;
import com.atguigu.crowd.api.RedisRemoteService;
import com.atguigu.crowd.config.VO.MemberLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.Ordered;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import javax.validation.constraints.Size;
import java.util.Date;
import java.util.Objects;


/*
@Component
@Slf4j
public class MyLogGateWayFilter implements GlobalFilter, Ordered {

    @Autowired
    private RedisRemoteService redisRemoteService;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpResponse response = exchange.getResponse();

        ResultEntity<String> username = redisRemoteService.getRedisStringValueByKeyRemote("username");
        if(username.getData() == null) {
            String redirectURL = "http://localhost/auth/welcome/member/login";
            response.getHeaders().set(HttpHeaders.LOCATION, redirectURL);
            response.setStatusCode(HttpStatus.SEE_OTHER);
            response.getHeaders().add("Content-Type", "text/plain;charset=UTF-8");
            return response.setComplete();
        }
        //4.如果存在,继续执行
        return chain.filter(exchange); //继续向下执行
    }

    // 设置优先级的，不用太在意
    @Override
    public int getOrder() {
        return 0;
    }
}*/
